-- DATETIME cases
EXEC babel_4214_datetime_to_int_proc
GO

SELECT babel_4214_datetime_to_int_function()
GO

SELECT CONVERT(BIT, ISNULL(CAST('1900-01-10 11:00:50.677' AS DATETIME), 0));
GO

SELECT CAST(CAST('1900-01-10 11:00:50.699' AS DATETIME) AS FLOAT);
GO

SELECT CAST(CAST('1900-01-10 11:00:50.699' AS DATETIME) AS FLOAT) +.999999;
GO

SELECT CAST(CAST(CAST('1900-01-10 11:00:50.699' AS DATETIME) AS FLOAT) AS DATETIME);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS BIT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS TINYINT);
GO

SELECT CAST(CAST('1910-01-10 12:56:50.699' AS DATETIME) AS SMALLINT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS INT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS BIGINT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS REAL);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS FLOAT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS NUMERIC(18,4));
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS NUMERIC(18,6));
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS DECIMAL(18,5));
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS BIT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS TINYINT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS INT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS BIGINT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS REAL);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS FLOAT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS NUMERIC(18,4));
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS NUMERIC(18,6));
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS DECIMAL(18,5));
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS BIT);
GO

SELECT CAST(CAST(CAST('1900-01-10 12:56:50.699' AS DATETIME) AS sql_variant) AS TINYINT);
GO

SELECT CAST(CAST(CAST('1910-01-10 12:56:50.699' AS DATETIME) AS sql_variant) AS SMALLINT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS INT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS BIGINT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS REAL);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS FLOAT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS NUMERIC(18,6));
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS DATETIME) AS sql_variant) AS DECIMAL(18,5));
GO

-- Negative dates, i.e. dates before 1900-01-01

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS BIT);
GO

SELECT CAST(CAST('1899-12-21 12:56:50.677' AS DATETIME) AS TINYINT);
GO

SELECT CAST(CAST('1890-12-21 12:56:50.677' AS DATETIME) AS SMALLINT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS INT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS BIGINT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS REAL);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS FLOAT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS NUMERIC(18,4));
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS NUMERIC(18,6));
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS DATETIME) AS DECIMAL(18,5));
GO

-- SMALLDATETIME cases
EXEC babel_4214_smalldatetime_to_int_proc
GO

SELECT babel_4214_smalldatetime_to_int_function();
GO

SELECT CONVERT(BIT, ISNULL(CAST('1900-01-10 11:00:50.699' AS SMALLDATETIME), 0));
GO

SELECT CAST(CAST('1900-01-10 11:00:50.699' AS SMALLDATETIME) AS FLOAT);
GO

SELECT CAST(CAST('1900-01-10 11:00:50.699' AS SMALLDATETIME) AS FLOAT) +.999999;
GO

SELECT CAST(CAST(CAST('1900-01-10 11:00:50.699' AS SMALLDATETIME) AS FLOAT) AS SMALLDATETIME);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS BIT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS TINYINT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS SMALLINT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS INT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS BIGINT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS REAL);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS FLOAT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS NUMERIC);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS NUMERIC(18,4));
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS NUMERIC(18,6));
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS NUMERIC(18,10));
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS DECIMAL);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS DECIMAL(18,5));
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS BIT);
GO

SELECT CAST(CAST('1900-01-10 12:56:50.699' AS SMALLDATETIME) AS TINYINT);
GO

SELECT CAST(CAST('1910-01-10 12:56:50.699' AS SMALLDATETIME) AS SMALLINT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS INT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS BIGINT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS REAL);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS FLOAT);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS NUMERIC);
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS NUMERIC(18,4));
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS NUMERIC(18,6));
GO

SELECT CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS DECIMAL(18,5));
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS BIT);
GO

SELECT CAST(CAST(CAST('1900-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS TINYINT);
GO

SELECT CAST(CAST(CAST('1910-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS SMALLINT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS INT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS BIGINT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS REAL);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS FLOAT);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS DOUBLE PRECISION);
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS NUMERIC(18,6));
GO

SELECT CAST(CAST(CAST('2023-01-01 12:56:50.699' AS SMALLDATETIME) AS sql_variant) AS DECIMAL(18,5));
GO

-- Negative dates are not supported by SMALLDATETIME, i.e. dates before 1900-01-01
SELECT CAST(CAST('1890-01-01 12:56:50.677' AS SMALLDATETIME) AS INT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS SMALLDATETIME) AS BIGINT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS SMALLDATETIME) AS FLOAT);
GO

SELECT CAST(CAST('1890-01-01 12:56:50.677' AS SMALLDATETIME) AS NUMERIC(18,6));
GO